package manage.utils;

import net.lcheng.service.SysPermissionsService;
import net.lcheng.vo.SysPermissionsModel;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.ui.Model;

import java.util.List;


/**
 * Created by zwr on 16/5/26.
 */
public class ControllerUtils {
    public static void common(Model model, SysPermissionsService permissionsService, String pKey) {
        Subject currentUser = SecurityUtils.getSubject();
        if(currentUser.isAuthenticated()) {
            String userName = currentUser.getPrincipals().toString();
            model.addAttribute("userName",userName);
            List<SysPermissionsModel> permissionsList = permissionsService.getModelByUserName(userName);
            model.addAttribute("permissions", permissionsList);
        }
        model.addAttribute("sub", pKey);
    }
}
